<?php
    //include "../database.php";
    //db_connect();

    //For form to send data
    if(empty($page)) {
	$page = "addSubdivisionsToMeasure.php";
    }

    $sql = "SELECT * FROM directions ORDER BY id";
    $directions = mysql_query($sql);

    if(!empty($_POST)) {
	$measure = mysql_real_escape_string($_POST['measure']);
	$code = mysql_real_escape_string($_POST['code']);
	$direction = mysql_real_escape_string($_POST['direction']);

	$sql = "INSERT INTO support (code, title, direction_id) VALUES ('$code', '$measure', '$direction')";
	mysql_query($sql);
    }

    //db_close();
?>

<label for="error" style="color:red;"><?php if(!empty($error_string)) echo $error_string; ?></label>
<label for="inform" style="color:green;"><?php if(!empty($msg)) echo $msg; ?></label>

<form name="SubdivisionsToMeasure" action="<?php echo $page;?>" method="POST">
    <label for="measure">Paramos priemonė:</label>
    <input type="text" name="measure"/><br/>
    <label for="code">Kodas:</label>
    <input type="text" name="code"/><br/>
    <label for="direction">Kryptis:</label>
    <select name="direction">
	<?php
	    while($direction = mysql_fetch_assoc($directions)) {
		print "<option value='".$direction['id']."'>";
		print $direction['title'];
		print "</option>";
	    }
	?>
    </select><br/>

    <input type="submit" name="submit" value="Susieti"/>
</form>
<a href="index.php?changes">Atgal</a>